<?php

namespace App\Models\Setting;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class GlobalSetting extends Model
{
    protected $table = 'global_setting';

    public $timestamps = false;

    protected $fillable = [
        'name',
        'result',
    ];

    public function increase($needUpdateDb) {
        DB::beginTransaction();
        $number = ++$this->result;
        $this->save();
        if ($needUpdateDb) DB::commit();
        else DB::rollBack();

        return $number;
    }

    public static function find($name): self {
        return self::where('name', $name)->first();
    }
}
